package com.blb.day1thread;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class ThreadTest {

    public static void main(String[] args) {
        //创建线程对象
        MyThread myThread = new MyThread();
//        myThread.setName("张三");
        //启动线程
        myThread.start();

        //实现Runnable方式
//        MyRunnable myRunnable = new MyRunnable();
//        Thread thread = new Thread(myRunnable);
//        thread.start();
//        new Thread(new Runnable() {
//            @Override
//            public void run() {
//                System.out.println("我是匿名内部类： " + Thread.currentThread().getName());
//            }
//        }).start();
        new Thread(() ->
                System.out.println("我是Lambda： " + Thread.currentThread().getName()))
                .start();

        //创建Callable对象
        MyCallable myCallable = new MyCallable();
        //创建FutureTask对象
        FutureTask<Long> task = new FutureTask<>(myCallable);
        //创建线程对象
        Thread thread1 = new Thread(task);
        //启动线程
        thread1.start();
        //获得结果
        try {
            System.out.println("获得结果:"+task.get());
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
    }
}
